package logic.SysPerson

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.ad.domain.SysPerson
import cn.ibizlab.core.ad.service.SysPersonService
import cn.ibizlab.core.authorization.domain.SysRoleMember
import cn.ibizlab.core.authorization.service.SysRoleMemberService
import cn.ibizlab.core.authorization.domain.SysRole
import cn.ibizlab.core.authorization.service.SysRoleService
import cn.ibizlab.core.authorization.domain.SysRole
import cn.ibizlab.core.authorization.service.SysRoleService
import cn.ibizlab.core.authorization.domain.SysRoleMember
import cn.ibizlab.core.authorization.service.SysRoleMemberService
import cn.ibizlab.core.authorization.domain.SysRoleMember
import cn.ibizlab.core.authorization.service.SysRoleMemberService
import cn.ibizlab.core.authorization.domain.SysRole
import cn.ibizlab.core.authorization.service.SysRoleService
import cn.ibizlab.core.authorization.domain.SysRole
import cn.ibizlab.core.authorization.service.SysRoleService
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  初始化人员权限
 */
class Init {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    //系统角色成员列表
    def _member_list = new SysRoleMember()
    //遍历系统角色临时变量
    def _role_sub = new SysRole()
    //系统角色列表
    def _sys_role_list = new SysRole()
    //系统角色成员
    def _sys_role_member = new SysRoleMember()
    //系统角色成员过滤器
    def _sys_role_member_filter = new SysRoleMember()
    //系统角色
    def _sys_role = new SysRole()
    //filterRole
    def _filterrole = new SysRole()
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        
        
        
        
        
        
        
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //连接名称
        if(true) {
            debugparam1()
        }
    }

    //调试逻辑参数
    def debugparam1() {
        println _default
        //连接名称
        if(((RuleUtils.test(_default, 'ISNULL', 'null')))) {
            throwexception1()
        }
        //连接名称
        else if(((RuleUtils.test(_default, 'ISNOTNULL', 'null')))) {
            prepareparam1()
        }
    }

    //实体数据查询
    def dedataquery1() {
        //DEDataQuery 暂未实现
        if(((RuleUtils.test(_member_list.get('size'), 'EQ', '0')))) {
            prepareparam3()
        }
    }

    //抛出异常
    def throwexception1() {
        throw new RuntimeException('初始化人员权限失败，未传入人员信息')
        if(true) {
            end1()
        }
    }

    //准备参数
    def prepareparam1() {
        _filterrole.set("n_dc_eq", _default.get("dc"))
        _filterrole.set("n_authority_eq", "ROLE_USERS")

        if(true) {
            dedataquery2()
        }
    }

    //实体数据查询
    def dedataquery2() {
        //DEDataQuery 暂未实现
        if(true) {
            loopsubcall2()
        }
    }

    //循环子调用
    def loopsubcall2() {
    //未支持的处理节点

        //连接名称
        if(true) {
            prepareparam2()
        }
        //连接名称
        else if(true) {
            end1()
        }
    }

    //准备参数
    def prepareparam2() {
        _sys_role_member_filter.set("n_role_id_eq", _role_sub.get("id"))
        _sys_role_member_filter.set("n_member_uid_eq", _default.get("id"))
        _sys_role_member_filter.set("member_type", "inetOrgPerson")

        if(true) {
            dedataquery1()
        }
    }

    //结束
    def end1() {

    }

    //准备参数
    def prepareparam3() {
        _sys_role_member.set("member_type", "inetOrgPerson")
        _sys_role_member.set("member_uid", _default.get("id"))
        _sys_role_member.set("member_name", _default.get("display_name"))

        if(true) {
            deaction2()
        }
    }

    //实体行为
    def deaction2() {
        SpringContextHolder.getBean(SysRoleMemberService.class).create(_sys_role_member)

    }

}
